require 'json';
 
class Ticker
  def initialize(high, low, volume, buy, sell, last)
    @high = high
    @low = low
    @volume = volume
    @buy = buy
    @sell = sell
    @last = last
  end
  
  def to_s
    "Ticker High: #{@high}, Low: #{@low}, Volume  #{@volume} \n Buy: #{@buy}, Sell: #{@sell}, Last  #{@last}"
  end

  def to_json(*a)
    {
      'ticker' => {'high' => @high, 'low' => @low, 'vol' => @volume, 'buy' => @buy, 'sell' => @sell, 'last' => @last }
    }.to_json(*a)
  end
  
  def self.parse_json(json_string)
    hash = JSON.parse(json_string)['ticker']
    new(hash['high'], hash['low'], hash['vol'], hash['buy'], hash['sell'], hash['last'])
  end
  
  def Last
    return @last
  end
end